

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%--/**
* 创建作者:   方 堃
* 创建日期:   8:32 2019/7/23
* 方法介绍:  标准树结构
* @return
*/--%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>设备类型</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/eleTree.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/js/limstree.js?v=2019080601" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <%--<script type="text/javascript" src="/lims/layer/layer.js?20201106"></script>--%>
    <style>
        .layui-card-header{
            border-bottom: 1px solid #eee;
            /*background: #fff;*/
            /*margin-top: 5px;*/
        }
        .main-row{
            display: flex;
            width: 100%;
            box-sizing: border-box;
            padding: 0 10px;
            font-size: 15px;
            line-height: 16px;
            margin-top: 15px;
        }
        .side-col{
            width: 30%;
            padding-right: 12px;
        }

        .panel {
            position: relative;
            /*margin-bottom: 20px;*/
            background-color: #fff;
            border: 1px solid transparent;
            border-radius: 4px;
            -webkit-box-shadow: 0 1px 1px rgba(0,0,0,.05), 0 2px 6px 0 rgba(0,0,0,.045);
            box-shadow: 0 1px 1px rgba(0,0,0,.05), 0 2px 6px 0 rgba(0,0,0,.045);
        }
        .panel-heading {
            padding: 12px 48px 12px 20px;
            border-bottom: 1px solid transparent;
            border-top-left-radius: 3px;
            border-top-right-radius: 3px;
        }
        .panel-title {
            font-size: 14px;
            font-weight: 700;
            line-height: 20px;
            cursor: pointer;
        }
        .panel-body{
            padding: 20px;
            padding-top: 0;
        }
        .main-col{
            width: 70%;
        }

        .row-module + .row-module {
            margin-top: 5px;
        }

        .row-module {
            max-width: 550px;
            min-width: 400px;
        }
        .table-row {
            display: table;
            width: 100%;
            table-layout: fixed;
        }
        .col-module{
            min-width: 200px;
        }
        .col-shorts {
            width: 110px;
        }
        .table-form>tbody>tr>td, .table-form>tbody>tr>th, .table-form>tfoot>tr>td, .table-form>thead>tr>th {
            padding: 7px;
            vertical-align: middle;
            border-bottom: none;
        }
        .table td, .table th {
            padding: 8px 10px;
            line-height: 1.42857143;
            vertical-align: top;
            border-bottom: 1px solid #cbd0db;
            -webkit-transition: background .2s cubic-bezier(.175,.885,.32,1);
            -o-transition: background .2s cubic-bezier(.175,.885,.32,1);
            transition: background .2s cubic-bezier(.175,.885,.32,1);
        }
        .text-middle{
            font-size: 14px;
        }
        .text-middle img{
            width: 21px;
            margin-bottom: 4px;
        }
        .col-actions {
            width: 88px;
            padding-left: 5px;
        }
        .iptbox{
            display: flex;
            margin: 10px 0;
        }
        .longs{
            width: 310px;
        }
        .shorts{
            width: 220px;
        }
        .pnul{
            width: 60px;
        }
        .btnls{
            display: flex;
            align-items: center;
            margin-left: 5px;
        }
        .rtfix{
            overflow-y: auto;
        }

        /*滚动条样式*/
        .rtfix::-webkit-scrollbar {/*滚动条整体样式*/
            width: 4px;     /*高宽分别对应横竖滚动条的尺寸*/
            height: 4px;
        }
        .rtfix::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
            border-radius: 5px;
            -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
            background: rgba(0,0,0,0.2);
        }
        .rtfix::-webkit-scrollbar-track { /*滚动条里面轨道*/
            -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            border-radius: 0;
            background: rgba(0, 0, 0, 0.1);
        }
        .layui-layer-btn .layui-layer-btn0{
            background-color: #009688 !important;
            border-color: #009688 !important;
        }
        .layui-layer-btn .layui-layer-btn1{
            background-color: #FF5722 !important;
            border-color: #FF5722 !important;
            color: #fff;
        }
        #hide{
            display: none;
        }
        .layui-colla-item {
            position: relative;
        }
    </style>
</head>
<body>
<%--<div class="layui-card-header">模块维护::实验室管理系统</div>--%>

<div class="main-row">
    <div class="side-col">
        <div class="panel  rtfix">
            <div class="panel-heading" id="lefttitle">
                <div class="panel-title maintit">设备类型<button id="addlBtn" class="layui-btn layui-btn-xs" style="float: right;margin-top: -1px;">新增</button></div>

            </div>
            <div class="panel-body">
                <%--<div id="test9" class="demo-tree demo-tree-box"></div>--%>
                <div class="eleTree ele1" lay-filter="data1"></div>
            </div>
        </div>
    </div>
    <div class="main-col">
        <div class="panel  rtfix">
            <div class="panel-heading rtfix">
                <div class="panel-title">维护下级设备类型</div>
                <div class="panel-body">
                    <table class="table table-form table-auto">
                        <tbody>
                        <tr class="terbox">
                            <td class="text-middle text-right with-padding">
                                <span><a href="jacascript:;" class="coname">设备类型</a><img src="/img/xy.png" alt=""></span>
                            </td>
                            <td>
                                <div id="sonModule">
                                    <div class="iptbox">
                                        <%--<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="模块名称" class="layui-input longs">--%>
                                        <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="简称" class="layui-input shorts">
                                        <div class="btnls">
                                            <button type="button" class="layui-btn layui-btn-sm limsAdd"><i class="layui-icon"></i></button>
                                            <button type="button" class="layui-btn layui-btn-sm limsDel"><i class="layui-icon"></i></button>
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td colspan="2" class="form-actions">
                                <button type="button" class="layui-btn layui-btn-normal" id="save">保存</button>
                                <input type="hidden" name="maxOrder" id="maxOrder" value="0">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <%--<div class="main-col">--%>
    <%--<div class="panel">--%>
    <%--<div class="panel-heading rtfix">--%>
    <%--&lt;%&ndash;<div class="panel-title">&ndash;%&gt;--%>
    <%--&lt;%&ndash;<button type="button" id="edit" class="layui-btn" style="width: 90px;height: 30px;line-height: 30px;padding: 0 5px">编辑能力项</button>&ndash;%&gt;--%>
    <%--&lt;%&ndash;<button type="button" id="com"class="layui-btn layui-btn-normal"  style="width: 90px;height: 30px;line-height: 30px;padding: 0 5px">同步能力项</button>&ndash;%&gt;--%>
    <%--&lt;%&ndash;</div>&ndash;%&gt;--%>

    <%--<div class="panel-body" style="padding: 0">--%>
    <%--<div id="hide" style="display: none; width: 100%; height: 50px; line-height: 50px;padding-left: 10px; font-size: 20px;">--%>
    <%--<span>能力项</span>--%>
    <%--</div>--%>
    <%--<div class="layui-collapse"></div>--%>
    <%--&lt;%&ndash;<table class="layui-table" lay-skin="line" id="refertable" lay-filter="refertable">&ndash;%&gt;--%>
    <%--&lt;%&ndash;<colgroup>&ndash;%&gt;--%>
    <%--&lt;%&ndash;<col width="150">&ndash;%&gt;--%>
    <%--&lt;%&ndash;<col width="150">&ndash;%&gt;--%>
    <%--&lt;%&ndash;<col width="200">&ndash;%&gt;--%>
    <%--&lt;%&ndash;<col>&ndash;%&gt;--%>
    <%--&lt;%&ndash;</colgroup>&ndash;%&gt;--%>
    <%--&lt;%&ndash;<thead>&ndash;%&gt;--%>
    <%--&lt;%&ndash;<tr id="hide" style="display: none;">&ndash;%&gt;--%>
    <%--&lt;%&ndash;<th colspan="4" style="font-weight: 700;font-size: 16px;">能力项</th>&ndash;%&gt;--%>


    <%--&lt;%&ndash;</tr>&ndash;%&gt;--%>
    <%--&lt;%&ndash;<tr>&ndash;%&gt;--%>
    <%--&lt;%&ndash;</tr>&ndash;%&gt;--%>
    <%--&lt;%&ndash;</thead>&ndash;%&gt;--%>
    <%--&lt;%&ndash;<tbody class="">&ndash;%&gt;--%>
    <%--&lt;%&ndash;<div class="layui-collapse"></div>&ndash;%&gt;--%>
    <%--&lt;%&ndash;&lt;%&ndash;<th colspan="4"></th>&ndash;%&gt;&ndash;%&gt;--%>
    <%--&lt;%&ndash;</tbody>&ndash;%&gt;--%>
    <%--&lt;%&ndash;</table>&ndash;%&gt;--%>
    <%--</div>--%>
    <%--</div>--%>
    <%--</div>--%>
    <%--</div>--%>
</div>



<script type="text/javascript">
    $('.rtfix').css('max-height',autodivheight()-40)
    var el
        ,aldata
        ,nodefun = new Classmeth()
        ,newstr='<div class="iptbox mnodec" pid="">'+
        '<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="序号" class="layui-input pnul">'+
        '<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="名称" class="layui-input shorts">'+
        //'<input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="备注" class="layui-input longs">'+
        '<div class="btnls">'+
        '<button type="button" class="layui-btn layui-btn-primary layui-btn-sm limsAdd"><i class="layui-icon"></i></button>'+
        '<button type="button" class="layui-btn layui-btn-primary layui-btn-sm limsDel"><i class="layui-icon"></i></button>'+
        '</div>'+
        '</div>';
    var getChildData;
    var resultTypeDatas;
    var resultTypeData;
    var idd;
    var  alltable=[];
    var idss="";
    layui.use(['table','layer','form','eleTree','element'], function(){
        var table = layui.table
            ,layer = layui.layer
            ,$ = layui.jquery
            ,eleTree = layui.eleTree
            ,element=layui.element

//        初始化渲染
        el = eleTree.render({
            elem: '.ele1',
            highlightCurrent: true,
            // draggable:true,
            showLine:true,
            url:'/equipmentType/showParentEquipmentType',
            where:{"result":"1"},
            emptText: "暂无数据",
            contextmenuList: [/*{eventName: "addcode", text: "编码"},*/'add.async',{eventName: "edit", text: "编辑"},'remove'],
            lazy: true,
            load: function(data,callback) {
                $.post('/equipmentType/showChildEquipmentType?equipTypeId='+data.id+'&result='+1,function (res) {
                    callback(res.data);//点击节点回调
                    $('#sonModule').html(updateList(res.data)+newstr);
                    if(res.data) nodefun.objLen = res.data.length
                    else nodefun.objLen = 0;
                })
            },
            done:function (data) { //渲染完成回调
                $('#sonModule').html(updateList(data.data)+newstr).attr('parent',0);
                if(data.data.length >0) {
                    nodefun.objLen = data.data.length;
                    $("#addlBtn").css("display","none");
                }
                else{
                    nodefun.objLen = 0;
                    $(".ele1").text("暂无数据");
                    $(".ele1").css("text-align","center");
                    $("#addlBtn").css("display","block");
                }
            }
        });
        $("#addlBtn").click(function () {
            layer.open({
                type: 1
                ,skin: 'layui-layer-rim'
                ,area: ['350px', '150px']
                ,title:'请输入设备类型'
                ,btn: ['确定','取消']
                ,maxmin: true
                ,content: '<input type="text" class="layui-input" id="eqType" style="width: 300px;padding: 0 10px;margin: 5px auto;" />'
                ,yes:function(index, layero){
                    layer.close(index);
                    var val = $("#eqType").val();
                    var obj = {
                        pId:0
                        ,type:0
                        ,label:val
                    }
                        ,newVal='';
                    $.post('/equipmentType/addEquipType',obj,function (res) {
                        window.location.reload();
                    })
                }
            })
        })
        // 节点点击事件
        eleTree.on("nodeClick(data1)",function(d) {
            console.log(d);
            idss="";
            var obj = d.data.currentData
            var pid = obj.equipTypePid;
            idd=obj.id;
            var str = str = updateList(obj.children);
            $('.coname').html(obj.label);
            $('#sonModule').attr('parent',obj.id);
            $('#sonModule').html(str+newstr);
            // if(pid == 0){//如果pid为空则str数据不渲染
            //     str = "";
            //     $("#hide").css("display","none");
            // }else{
            //     $("#hide").css("display","block");
            //     $.get('/equipmentType/showEquipType',{"equipTypeId":idd}, function (res) {
            //     resultTypeDatas = res.data[0];
            //         resultTypeData=res.data[1];
            //         for(var j=0;j<resultTypeData.length;j++){
            //             idss+=resultTypeData[j].capyId+",";
            //         }
            //     for (var i = 0; i < resultTypeDatas.length; i++) {
            //         str += '<div class="layui-colla-item" style="position: relative">' +
            //             '<h2  class="layui-colla-title" typeCode="' + resultTypeDatas[i].typeCode + '" flag="0">' + resultTypeDatas[i].typeName + '</h2>' +
            //             '<div class="layui-colla-content">' +
            //             '<div class="layui-card-body" class ="tyss">' +
            //             '<table id="' + resultTypeDatas[i].typeCode + '" lay-filter="' + resultTypeDatas[i].typeCode + 'Filter" style="width: 100%;"></table>' +
            //             '</div>' +
            //             '</div>' +
            //             '</div>'
            //     }
            //     $('.layui-collapse').html(str);
            //     // $(".main-row").find("h2").click();
            //     // $(".main-row").find("h2").click();
            //     element.render();
            // })
            // }
            nodefun.pid = obj.equipTypePid;
            nodefun.id = obj.id;

        })
        //点击事件
        $(document).on('click', '.layui-colla-title', function () {
            var typeCode = $(this).attr('typeCode');
            var datas=[];
            for( var i=0;i<resultTypeData.length;i++){
                if(typeCode==resultTypeData[i].typeCode){
                    datas.push(resultTypeData[i])
                }
            }
            if ($(this).attr('flag') == 0) {
                var alltbobj = {};
                var str;
                //判断pid是否为0 如果是 就让str等于空，否则就渲染数据
                if(datas.length>0){
                    $.each(datas,function (i,v) {
                        if(datas[i] != null){
                            str += '<tr style="height: 37px; line-height: 37px; border-bottom: 1px solid #e6e6e6; padding-left: 20px"><td data-cid='+datas[i].capyId+'>'+datas[i].capyName+'</td></tr>'
                        }
                    })
                    $('#'+typeCode).html(str)
                    layui.form.render()
                }

                alltbobj.name = typeCode;
                alltbobj.tab = intabls;
                alltable.push(alltbobj)
                $(this).attr('flag', '1');

            }






        })
        // 添加节点之前事件
        eleTree.on("nodeInsertBefore(data1)",function(d) {
            var obj = {
                pId:d.data.equipTypePid
                ,id:d.data.id
                ,sort:d.data.equipSort
                ,type:0
                ,label:d.newData.label
            }
            $.post('/equipmentType/addEquipType',obj,function (res) {
                if(res.msg=="空值无法添加"){
                    layer.msg(res.msg);
                }
                else{
                    var data = res.data;
                    $.each(data, function(i,val){
                        el.updateKeySelf(val.id,val);   //更新当前节点
                        if(data[i].label == d.newData.label){
                            el.insertBefore(d.data.id,val);   //添加节点之前
                            d.stop()
                        }
                    });
                    codeframe(res.object);
                    $('#sonModule').html(updateList(data)+newstr);  // 右侧树更新
                    if(d.data.parentId == 0) $('.coname').html('标准类别');
                    else $('.coname').html(d.data.parentName);
                }
            })
        })
        // 添加子节点事件
        eleTree.on("nodeAppend(data1)",function(d) {
            if(d.newData.label == '未命名1')return d.stop();// 取消自动添加
            var obj = {
                pId:d.data.equipTypePid
                ,id:d.data.id
                ,sort:d.data.equipSort
                ,type:1
                ,label:d.newData.label
            }
                ,newVal='';
            $.post('/equipmentType/addEquipType',obj,function (res) {
                if(res.code == 1){              //异常提示（重名）
                    d.stop();// 取消自动添加
                    return layer.msg(res.msg)
                }
                var data = res.data;
                $.each(data, function(i,val){
                    if(data[i].label == d.newData.label) newVal = val
                    el.updateKeySelf(data[i].id,data[i]);
                });
                d.stop();// 取消自动添加
                el.append(d.data.id,newVal);//插入子节点
                codeframe(res.object)
                $('#sonModule').html(updateList(data)+newstr);  // 右侧树更新
            })
        })

        eleTree.on("nodeEdit(data1)",function(d) {
            var code="";
            if(d.data.equipTypeCode!=undefined){
                code=d.data.equipTypeCode;
            }
            layer.open({
                type: 1,
                skin: 'layui-layer-molv', //加上边框
                area: ['500px', '180px'], //宽高
                title: '类型名称编辑',
                maxmin: true,
                btn: ['提交', '取消'],
                content: '<div class="layui-form" >' +
                    '<div class="inbox" style="margin-top: 30px;"><label class="layui-form-label">请输入类型名称</label><div class="layui-input-block">' +
                    '<input  id="name" name="name" style="width:300px; float: left"  class="layui-input"></div></div>' +
                    '</div>',
                success: function () {
                    $("#name").val(d.data.name);
                },
                yes:function(){
                    var name=$("#name").val();
                    if(name==undefined||name==null||name==""){
                        layer.msg("名称不能为空");
                        return false;
                    }
                    d.data.label=name;
                    $.ajax({
                        type: "post",
                        url: '/equipmentType/editEquipmentType',
                        dataType: "json",
                        data:{
                            equipType:JSON.stringify(d.data)
                        },
                        success:function (res) {
                            if(code!=""){
                                d.data.label =name + "("+code+")"
                            }else{
                                d.data.label = name
                            }
                            layer.closeAll();
                            layer.msg(res.msg);
                            d.data.name = name
                            el.updateKeySelf(d.data.id,d.data)
                        }
                    })
                }
            });
        })
        // 编码编辑/新增
        /*eleTree.on("nodeAddcode(data1)",function(d) {
            codeframe(d.data)
        })*/

        // 添加节点之后事件
        eleTree.on("nodeInsertAfter(data1)",function(d) {
            var obj = {
                pId:d.data.equipTypePid
                ,id:d.data.id
                ,sort:d.data.equipSort
                ,type:2
                ,label:d.newData.label
            }
            $.post('/equipmentType/addEquipType',obj,function (res) {
                if(res.msg=="空值无法添加"){
                    layer.msg(res.msg);
                }else{
                    var data = res.data;
                    $.each(data, function(i,val){
                        el.updateKeySelf(val.id,val);   //更新当前节点
                        if(data[i].label == d.newData.label){
                            el.insertAfter(d.data.id,val);//添加节点之后
                            d.stop()
                        }
                    });
                    codeframe(res.object);
                    $('#sonModule').html(updateList(data)+newstr);  // 右侧树更新
                    if(d.data.parentId == 0) $('.coname').html('标准类别');
                    else $('.coname').html(d.data.parentName);
                }
            })
        })

        var l = document.getElementsByClassName("eleTree-node");
        // 树节点被删除事件
        eleTree.on("nodeRemove(data1)",function(d) {
            console.log(d);
            var dt = d.data
                ,removele
                ,obj ={
                equipTypeId:dt.id
                ,pid:dt.equipTypePid
                ,id:dt.id
                ,isLeaf:dt.isLeaf
                ,sort:dt.equipSort
            }
                ,delobj ={
                equipTypeId:dt.id
            }
            if(dt.children<=0){
                obj.isLeaf = "true";
            }
            $.each($('.code'),function (i,v) {  //右侧同步删除
                if($($('.code')[i]).val() == dt.id) removele = $($('.code')[i]).parents('.iptbox');

            })
            d.stop(); // 取消删除
            console.log(obj);
            console.log(delobj);
            nodefun.del(obj,delobj,'/equipmentType/deleteEquipmentTypeById',removele,function (res) {
                if(l.length==0){
                    $(".ele1").text("暂无数据");
                    $(".ele1").css("text-align","center");
                    $("#addlBtn").css("display","block");
                }else{
                    $('.coname').html("");
                    $('#sonModule').html(newstr);
                }
            });

        })
        // 节点被拖拽事件
       /* eleTree.on("nodeDrag(data1)",function(d) {
            var nowData = d.current.data.currentData
                ,targetData = d.target.data.currentData
                ,obj = {
                id:nowData.id
                ,sort:nowData.equipSort
                ,pid:nowData.equipTypePid
                ,mid:targetData.id
            }
            $.post('/equipmentType/changeEquipmentType',obj,function (res) {
                var data = res.data;
                el.updateKeySelf(data.id,data);
                $.each(data, function(i,val){
                    el.updateKeySelf(val.id,val);   //更新当前节点
                });
                $('.coname').html(targetData.label);
                $('#sonModule').html(updateList(data)+newstr);  // 右侧树更新
            })
        })*/
    });

    //    ***********************************     右侧列表部分   ************************************

    // //    右侧列表删除
    // $(document).on('click','.limstreeDel',function () {
    //     var isLeaf = $(this).attr('isLeaf');
    //     var id = $(this).attr('cid');
    //     var ele = $(this).parents('.iptbox');
    //     nodefun.del(id,isLeaf,'/equipmentType/deleteEquipmentTypeById',ele);
    // })
    $(document).on('click','.limstreeDel',function () {
        var isLeaf = $(this).attr('isLeaf')
            , id = $(this).attr('cid')
            , sort = $(this).attr('sort')
            , ele = $(this).parents('.iptbox')
            , obj = {
            equipTypeId: id
            , id: id
            , isLeaf: isLeaf
            , pid: nodefun.pid
            , sort: sort
        }
            , delobj = {
            equipTypeId: id
        };
        nodefun.del(obj, delobj, '/equipmentType/deleteEquipmentTypeById', ele, function (res) {
            if (res.data.length > 0) {
                $('#sonModule').html(updateList(res.data)  + newstr);
            }
        })
    })
       //右侧列表保存/新增/修改
    $('#save').click(function () {
        var iptbox = $('.iptbox')
            ,iptlist = [],obj={},idList=[]
            ,pid = $('#sonModule').attr('parent')
        for(var i=0;i<iptbox.length;i++){
            var iptobj = {};
            iptobj.equipSort = $($(iptbox)[i]).find('.pnul').val();
            iptobj.label = $($(iptbox)[i]).find('.shorts').val();
            //iptobj.equipTypeCode = $($(iptbox)[i]).find('.longs').val();
            iptobj.id = $($(iptbox)[i]).find('.code').val() ?$($(iptbox)[i]).find('.code').val():'';
            iptlist.push(iptobj)
            if(iptobj.id) idList.push(Number(iptobj.id))
        }
        //  判断是否重名
        for(var i =0; i<iptlist.length; i++){
            if(iptlist[i].label != ''){
                if(!obj[iptlist[i].label]) obj[iptlist[i].label] = true;
                else return layer.msg("名称不可重复")
            }
        }
        var ipl = [];
        for(var j=0;j<iptlist.length;j++){
            if(iptlist[j].equipSort == ""&&iptlist[j].label == ""){

            }else{
                ipl.push(iptlist[j]);
            }
        }
        var indexPage = layui.layer.load(1);
        $.post('/equipmentType/addEquType',{pid:pid,json:JSON.stringify(ipl)},function (res) {
            layer.close(indexPage);
            layer.msg(res.msg);
            var residList=[];
            var data = res.data
            for(var i=0;i<data.length;i++){
                residList.push(data[i].id)
            }
            if(res.code==1){
                return false;
            }else{
                if(pid != 0 && idList.length != residList.length){
                    $.each(data,function(idx,item) {
                        if(idList.indexOf(item.id)<0){
                            el.append(pid,item);//插入子节点
                        }
                    })
                    $('#sonModule').html(updateList(data)+newstr)
                    idList=[]
                }else {
                    window.location.reload()
                }
            }
        })
        // var iptbox = $('.iptbox')
        //     ,iptlist = []
        //     ,pid = $('#sonModule').attr('parent')
        // for(var i=0;i<iptbox.length;i++){
        //     var iptobj = {};
        //     iptobj.standTypeSort = $($(iptbox)[i]).find('.pnul').val();
        //     iptobj.label = $($(iptbox)[i]).find('.shorts').val();
        //     iptobj.memo = $($(iptbox)[i]).find('.longs').val();
        //     iptobj.id = $($(iptbox)[i]).find('.code').val() ?$($(iptbox)[i]).find('.code').val():'';
        //     iptlist.push(iptobj)
        // }
        // $.post('/projstand/addAndEditStandType',{pid:pid,json:JSON.stringify(iptlist)},function (res) {
        //     layer.msg(res.msg);
        //     window.location.reload()
        // })
    })
           //更新右侧列表
    function updateList(obj) {
        var str = '';
        if (obj){
            for(var i=0;i<obj.length;i++){
                str+='<div class="iptbox">'+
                    '<input type="text" name="title" lay-verify="title" autocomplete="off" value="'+obj[i].equipSort+'" class="layui-input pnul">'+
                    '<input type="text" name="title" lay-verify="title" autocomplete="off" value="'+obj[i].label+'" class="layui-input shorts">'+
                    /*'<input type="text" name="title" lay-verify="title" autocomplete="off" value="'+a(obj[i].memo)+'" class="layui-input longs">'+*/
                    '<input type="hidden" value="'+obj[i].id+'" class="code">'+
                    '<div class="btnls">'+
                    '<button type="button" cid="'+obj[i].id+'" isLeaf="'+obj[i].isLeaf+'" class="layui-btn layui-btn-primary layui-btn-sm limstreeDel"><i class="layui-icon"></i></button>'+
                    '</div>'+
                    '</div>'+
                    '</div>';
            }
        }else str='';
        return str
    }

    //       加载根树
    $('.maintit').click(function () {
        el.reload();
        $('.coname').html('标准类别');
        $('#sonModule').attr('parent',0);
        nodefun.pid = 0;
    })

    $(document).on('click','.limsAdd',function () {
        $('#sonModule').append(newstr);
    })

    $(document).on('click','.limsDel',function () {
        if($('.mnodec').length>1){
            $(this).parents('.iptbox').remove();
        }
    })
    function a(value) {
        if(value==undefined){
            return ""
        }
        return value
    }
    //点击编辑弹出设备能力项移动框
    // layui.use('layer', function(){
    //     var layer = layui.layer;
    //     //点击按钮事件  打开弹出框
    //     $("#edit").click(function(){
    //         idss="";
    //         // 如果id存在就弹出编辑框
    //         if(nodefun.pid !=0){
    //             layer.open({
    //                 type: 2
    //                 ,skin: 'layui-layer-rim'
    //                 ,area: ['850px', '520px']
    //                 ,title:'编辑'
    //                 ,btn: ['确定','取消']
    //                 ,maxmin: true
    //                 ,content: '/equipCapy/equiptypeDetail?id='+ nodefun.id
    //                 ,yes:function(index, layero){
    //                     layer.close(index);
    //                     // 父调用子页面的方法
    //                     var sta=$(layero).find("iframe")[0].contentWindow.getStr();
    //                     var idCodes=[]
    //                     for(var i=0;i<sta.length;i++){
    //                         for(var j=0;j<sta[i].children.length;j++){
    //                             var cc=sta[i].children[j].id+'';
    //                             idCodes.push(cc.substring(0,cc.length-3))
    //                         }
    //                     }
    //                     var ids="";
    //                     for(var m=0;m<idCodes.length;m++){
    //                         ids+=idCodes[m]+","
    //                     }
    //                     //获取子页面的数据，进行渲染
    //                     $.ajax({
    //                             type: "post",
    //                             url: "/equipmentType/addEquipTypeCapyByTypeId",
    //                             dataType: "json",
    //                             data:{
    //                                 equuipTypeCapyIds:ids,
    //                                 equipTypeId:nodefun.id
    //                             },
    //                             success: function (res) {
    //                                 $.get('/equipmentType/showEquipType',{"equipTypeId":idd}, function (res) {
    //                                     resultTypeDatas = res.data[0];
    //                                     resultTypeData = res.data[1];
    //                                     for(var j=0;j<resultTypeData.length;j++){
    //                                         idss+=resultTypeData[j].capyId+",";
    //                                     }
    //                                      var str="";
    //                                     for (var i = 0; i < resultTypeDatas.length; i++) {
    //                                         str += '<div class="layui-colla-item" style="position: relative">' +
    //                                             '<h2  class="layui-colla-title" typeCode="' + resultTypeDatas[i].typeCode + '" flag="0">' + resultTypeDatas[i].typeName + '</h2>' +
    //                                             '<div class="layui-colla-content">' +
    //                                             '<div class="layui-card-body" class ="tyss">' +
    //                                             '<table id="' + resultTypeDatas[i].typeCode + '" lay-filter="' + resultTypeDatas[i].typeCode + 'Filter" style="width: 100%;"></table>' +
    //                                             '</div>' +
    //                                             '</div>' +
    //                                             '</div>'
    //                                     }
    //                                     $('.layui-collapse').html(str);
    //                                     layui.element.render();
    //                                 })
    //                             }
    //                         })
    //                 }
    //             })
    //         }else {
    //             //如果id不存在就提示需要选中设备类型才能进行编辑
    //             layer.confirm('需要选中设备类型中一级菜单中的设备类型才能进行编辑',{
    //                     btn: ['确定','取消'] //按钮
    //                 }, function() {
    //                     layer.closeAll('dialog');
    //                 }
    //             );
    //         }
    //     })
    //     $("#com").click(function(){
    //         if(nodefun.pid!=0){
    //             // var sss = "";
    //             // $("[data-cid]").each(function(){
    //             //     sss += $(this).attr("data-cid") + ",";
    //             // })
    //             $.ajax({
    //                 type: "post",
    //                 url: "/equipmentType/togetherCapy",
    //                 dataType: "json",
    //                 data:{
    //                     equipCapyIds:idss,
    //                     equipTypeId:nodefun.id
    //                 },
    //                 success: function (res) {
    //                     if(res.code == 0){
    //                         layer.msg(res.msg);
    //                     }else{
    //                         layer.msg(res.msg);
    //                     }
    //                 }
    //             })
    //         }else {
    //             //如果id不存在就提示需要选中设备类型才能进行编辑
    //             layer.confirm('需要选中设备类型中一级菜单中的设备类型才能进行同步',{
    //                     btn: ['确定','取消'] //按钮
    //                 }, function() {
    //                     layer.closeAll('dialog');
    //                 }
    //             );
    //         }
    //     })
    // })

    //编码弹框事件
   /* function codeframe(d) {
        var code = "";
        if (d.equipTypeCode != undefined && d.equipTypeCode != null) {
            code = d.equipTypeCode
        }
        layer.open({
            type: 1,
            skin: 'layui-layer-molv', //加上边框
            area: ['500px', '180px'], //宽高
            title: '编码',
            maxmin: true,
            btn: ['提交', '取消'],
            content: '<div class="layui-form" >' +
                '<div class="inbox" style="margin-top: 30px;"><label class="layui-form-label">请输入编码</label><div class="layui-input-block">' +
                '<input  id="code" name="code" style="width:300px; float: left"  class="layui-input"></div></div>' +
                '</div>',
            success: function () {
                $("#code").val(code);
            },
            yes: function (index) {
                var codenew = $("#code").val();
                if (code == codenew) {
                    layer.closeAll();
                    return false;
                }
                var data = {
                    equipTypeId: d.id,
                    code: codenew,
                    pId: d.equipTypePid
                }
                $.post('/equipmentType/updateCode', data, function (res) {
                    layer.closeAll();
                    layer.msg(res.msg, {
                        icon: 6,
                        time: 600,
                        end: function () {
                            if (res.code == 0) {
                                d.id = data.equipTypeId;
                                if (codenew != undefined && codenew != ""){
                                    d.label = d.name + "(" + codenew + ")";
                                    d.equipTypeCode=codenew;
                                }else{
                                    d.label = d.name
                                }
                                el.updateKeySelf(d.id, d)
                            }
                        }
                    });
                })
            }
        })
    }*/
</script>

</body>



</html>